#!/usr/bin/env node
require("babel-register");
require('yargs') // eslint-disable-line
  .command('get [ecode]', ':get [ecode] config', (yargs) => {
    yargs
      .positional('ecode', {
        describe: 'ecode to get on',
        default: 'fingersoft'
      })
  }, (argv) => {
    if (argv.verbose)
     {
        console.info(`get config for :${argv.ecode}`)
     }
    getConfig(argv.ecode)
  })
  .option('verbose', {
    alias: 'v',
    default: false
  })
  .argv


function getConfig(ecode){
var fetch =require('node-fetch');
var host = "http://220.178.25.66:28100/interface";
host = "http://menhu.ishangban.com/interface"
fetch(`${host}/${ecode}/am/startup/getConfig`,{
headers:{
"Emp-Info":JSON.stringify({"platform":"ANDROID","version":"1.0","deviceId":"dennis.android"})
}})
	.then(res => res.json())
    .then(json=>{
        console.log(json.data)
        var fs = require('fs');
        fs.writeFile("project.json", JSON.stringify(json.data), function(err) {
            if(err) {
                return console.log(err);
            }

            console.log("The file was saved!");

        });
    })

}